package com.wobangkj.common.api.crud;

import com.wobangkj.common.model.crud.Company;
import com.wobangkj.common.service.CompanyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/company")
public class CompanyController {
    @Autowired
    private CompanyService companyService;

    @PostMapping(value = "/create")
    public Object create(@RequestBody Company data) {
        // 创建时间
        data.setCreatetime(Timestamp.valueOf(LocalDateTime.now()));
        return companyService.create(data);
    }

    @PutMapping(value = "/update")
    public Object update(@RequestBody Company company) {

        return companyService.update(company);
    }

    @DeleteMapping(value = "/delete/{id}")
    public Object delete(@PathVariable(value = "id") Long id) {
        return companyService.delete(id);
    }

    @GetMapping("/id")
    public Object id(Long id) {

        return companyService.id(id);
    }


    @GetMapping("/search")
    public Object search(@RequestParam(required = false) Map<String, Object> params, Company company) {
        return companyService.search(params, company);
    }

    //模糊查询

    @GetMapping("/findByNameLike/{company_name}")
    public List<Company> findByNameLike(@PathVariable(value = "company_name") String company_name){
        // 一定要加 "%"+参数名+"%"
        return companyService.findByNameLike(company_name);
    }

}
